package com.central.common.page;


import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 分页工具类
 *
 */
@Data

public class PageData<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private int pageStart; //current page number
    private int pageSize; //current page size
    private int totalPage; //total pages after pagination page   ((total-1)/pageSize) + 1
    //总记录数
    private int total;

    //列表数据
    private List<T> list = new ArrayList<>();


    public static <T> PageData<T> copy(IPage iPage, List<T> result) {
        PageData<T> pageBean = new PageData<>();
        pageBean.setList(result);
        pageBean.setTotal((int) iPage.getTotal());
        pageBean.setTotalPage((int)iPage.getPages());

        pageBean.setPageStart(Integer.parseInt(iPage.getCurrent() + ""));
        pageBean.setPageSize(Integer.parseInt(iPage.getSize() + ""));
        return pageBean;
    }

}